"""
日志 PO
"""

from pydantic import BaseModel

from models import POBase
from models.other import (
    RequestInfo,
    RequestRoute,
    ResponseInfo,
)
from my_typing import *
from utils.data_utils.special import ObjectIdStr
from utils.validator_utils.pydantic_validator.field import (
    CharField,
    NormalField,
)


class _TimeInfo(BaseModel):
    """ 时间信息 | Model """

    in_time: datetime = NormalField(..., title="请求时间")
    out_time: datetime = NormalField(..., title="响应时间")
    total_seconds: float = NormalField(..., title="使用时间（秒）")


class RequestLogPO(POBase):
    """ 请求日志 | PO """

    request_id: str = CharField(..., title="当前线程的请求 ID")
    request_info: RequestInfo = NormalField(..., title="请求信息")
    response_info: ResponseInfo = NormalField(..., title="响应信息")
    route_info: RequestRoute = NormalField(..., title="请求路由信息")
    time_info: _TimeInfo = NormalField(..., title="时间信息")
    trace_id: StrOrNone = CharField(title="链路 ID", min_length=40, max_length=41)
    user_id: ObjectIdStr | None = NormalField(..., title="用户 ID")
